package com.lidx.back.statistics.controller.admin;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.lidx.back.statistics.entity.Filter;
import com.lidx.back.statistics.entity.MaterialRecord;
import com.lidx.back.statistics.service.IFilterRecordService;
import com.lidx.back.statistics.service.IFilterService;

@Controller
@RequestMapping("/admin/filter")
public class FilterAdminController {
	@Autowired
	private IFilterRecordService filterService;
	
	@RequestMapping(value="list",method=RequestMethod.GET)
	public String filterPage(){
		return "filter/list";
	}
	
	@RequestMapping(value="list",method=RequestMethod.POST)
	public ModelAndView goFilterPage(@RequestParam(value="filterRecords") String action,
			@RequestParam String versionType,
			@RequestParam(required=false) String from,
			@RequestParam(required=false) String to){
		ModelAndView mav = new ModelAndView("filter/list");
		if(StringUtils.isNotBlank(action) && StringUtils.isNoneBlank(versionType)){
			mav.addObject("versionType", versionType);
			//if(StringUtils.isNoneBlank(to)&& StringUtils.isNoneBlank(from)){
				MaterialRecord record = new MaterialRecord();
				List<Object[]> list = filterService.getRecordsWithParams(action,versionType,from,to);
				mav.addObject("records", list);
			//}
		}
		
		return mav;
	}
}
